// 如何在其他地方使用这个方法？？？
// 1. vscode调试
// 2. CMakeLists.txt配置

#include "common/utils.hpp"
#include <queue>

// 一颗通用的二叉树
/*
            10
        6       16
      3   9  14    19  
*/
TreeNode* commonRoot = new TreeNode(10, new TreeNode(6, new TreeNode(3), new TreeNode(9)), new TreeNode(16, new TreeNode(14), new TreeNode(19)));

// 一颗通用的N叉树
/*
            1
        3   2   4
       5 6
*/
std::vector<NTreeNode*> children3 = {new NTreeNode(5), new NTreeNode(6)};
std::vector<NTreeNode*> children2 = {new NTreeNode(3, children3), new NTreeNode(2), new NTreeNode(4)};
NTreeNode* commonNRoot = new NTreeNode(1, children2);

// 测试用的int类型全局变量
int commonInt = 100;

void printTreeNode(TreeNode* root) {
    std::queue<TreeNode*> queue;

    if (root != nullptr) queue.push(root);

    while(!queue.empty()) {
        int size = queue.size();
        for (int i = 0; i < size; i++) {
            TreeNode* node = queue.front();
            queue.pop();
            std::cout << node->val << " ";

            if (node->left) queue.push(node->left);
            if (node->right) queue.push(node->right);
        }
        std::cout << "\n";
    }
}

// [1,2,2,3,null,null,3,4,null,null,4]
// std::vector<int> arr = {1,2,2,3,-1,-1,3,4,-1,-1,4};
// 根据数组来创建二叉树
TreeNode* createTreeNodeByArray(const std::vector<int>& arr) {
    if (arr.empty() || arr[0] == -1) return nullptr;

    std::vector<TreeNode*> nodes(arr.size(), nullptr);
    for (int i = 0; i < arr.size(); i++) {
        if (arr[i] != -1) nodes[i] = new TreeNode(arr[i]);
    }

    int pos = 1;
    for (int i = 0; i < arr.size(); i++) {
        if (nodes[i] != nullptr) {
            if (pos < arr.size()) nodes[i]->left = nodes[pos++];
            if (pos < arr.size()) nodes[i]->right = nodes[pos++];
        }
    }

    return nodes[0];
}